import { Input, Select } from 'antd';
import type { ITjFormItemProps } from '@/tjComponents/TjForm/TjFormItem';
import _ from 'lodash';
import TJSelect from '../TJSelect';

const settlementStatus = [
  {
    label: '正常结算',
    value: 1,
  },
];

const formItems = (
  optionsData: any,
  disabled: boolean,
  handleSelectChange: (value: string) => void,
): ITjFormItemProps[] => {
  const marketingUnit = _.get(optionsData, 'marketingUnit', []);
  const getListStatementTypeByProvinceId = _.get(
    optionsData,
    'getListStatementTypeByProvinceId',
    [],
  );
  const listTransactionAttributes = _.get(optionsData, 'listTransactionAttributes', []);

  const items: ITjFormItemProps[] = [
    {
      name: 'marketId|marketName',
      label: '交易中心',
      render: (
        <TJSelect
          options={marketingUnit}
          useDataObject={{ label: 'marketName', value: 'marketId' }}
          onChange={handleSelectChange}
        />
      ),
      rules: [
        { required: true, message: '请选择交易中心' },
        () => ({
          validator(_, value) {
            if (value === undefined) {
              return Promise.reject(null);
            } else if (value.marketName === undefined) {
              return Promise.reject(Error('请选择交易中心'));
            }
            return Promise.resolve();
          },
        }),
      ],
    },
    {
      name: 'statementTypeId|statementTypeName',
      label: '结算科目',
      render: (
        <TJSelect
          options={getListStatementTypeByProvinceId}
          useDataObject={{ label: 'statementTypeName', value: 'statementTypeId' }}
        />
      ),
      rules: [{ required: true, message: '请选择结算科目' }],
    },
    {
      name: 'statementCode',
      label: '交易类型编码',
      rules: [
        { required: true, message: '请输入交易类型编码' },
        { pattern: /^[0-9]*[1-9][0-9]*$/, message: '只能输入数字' },
      ],
      render: <Input disabled />,
    },
    {
      name: 'transactionAttributesOneName|transactionAttributesOneCode',
      label: '交易属性1(新)',
      render: (
        <TJSelect
          options={listTransactionAttributes.attributesOne}
          useDataObject={{
            label: 'transactionAttributesOneName',
            value: 'transactionAttributesOneCode',
          }}
        />
      ),
      rules: [
        { required: true, message: '请选择交易属性1(新)' },
        () => ({
          validator(_, value) {
            if (value === undefined) {
              return Promise.reject(null);
            } else if (value.transactionAttributesOneName === undefined) {
              return Promise.reject(new Error('请选择交易属性1(新)'));
            }
            return Promise.resolve();
          },
        }),
      ],
    },
    {
      name: 'transactionAttributesTwoName|transactionAttributesTwoCode',
      label: '交易属性2(新)',
      render: (
        <TJSelect
          options={listTransactionAttributes.attributesTwo}
          useDataObject={{
            label: 'transactionAttributesTwoName',
            value: 'transactionAttributesTwoCode',
          }}
        />
      ),
      rules: [
        { required: true, message: '请选择交易属性2(新)' },
        () => ({
          validator(_, value) {
            if (value === undefined) {
              return Promise.reject(null);
            } else if (value.transactionAttributesTwoName === undefined) {
              return Promise.reject(new Error('请选择交易属性2(新)'));
            }
            return Promise.resolve();
          },
        }),
      ],
    },
    {
      name: 'transactionAttributesThreeName|transactionAttributesThreeCode',
      label: '交易属性3(新)',
      render: (
        <TJSelect
          options={listTransactionAttributes.attributesThree}
          useDataObject={{
            label: 'transactionAttributesThreeName',
            value: 'transactionAttributesThreeCode',
          }}
        />
      ),
      rules: [
        { required: true, message: '请选择交易属性3(新)' },
        () => ({
          validator(_, value) {
            if (value === undefined) {
              return Promise.reject(null);
            } else if (value.transactionAttributesThreeName === undefined) {
              return Promise.reject(new Error('请选择交易属性3(新)'));
            }
            return Promise.resolve();
          },
        }),
      ],
    },
    {
      name: 'transactionAttributesFourName|transactionAttributesFourCode',
      label: '交易属性4(新)',
      render: (
        <TJSelect
          options={listTransactionAttributes.attributesFour}
          useDataObject={{
            label: 'transactionAttributesFourName',
            value: 'transactionAttributesFourCode',
          }}
        />
      ),
    },
    {
      name: 'dataTypeName|dataTypeCode',
      label: '数据类型',
      render: (
        <TJSelect
          options={listTransactionAttributes.dataType}
          useDataObject={{
            label: 'dataTypeName',
            value: 'dataTypeCode',
          }}
        />
      ),
      rules: [
        { required: true, message: '请选择数据类型' },
        () => ({
          validator(_, value) {
            if (value === undefined) {
              return Promise.reject(null);
            } else if (value.dataTypeName === undefined) {
              return Promise.reject(new Error('请选择数据类型'));
            }
            return Promise.resolve();
          },
        }),
      ],
    },
    {
      name: 'remark',
      label: '备注',
      rules: [{ max: 50, message: '输入内容不能超过50个字符' }],
      col: {
        span: 24,
      },
    },
  ];
  return items;
};

export { formItems, settlementStatus };
